﻿/********************************************************************************
** @ Date:2022/03/11
** @ Author: Gaojia
** @ Description:
线程基类
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef CThreadBase_H
#define CThreadBase_H
#include <QWaitCondition>
#include <QVector>
#include <QMutex>
#include<qthread.h>
class CThreadBase : public QThread
{
	Q_OBJECT

public:
	CThreadBase(QObject *parent);
	CThreadBase();
	virtual ~CThreadBase();
	void run() Q_DECL_OVERRIDE;
	void ThreadBegin();
	void ThreadStop();
	void ThreadPause();
	/**
	* @ Author: Gaojia
	* @ Description: 线程等待API
	*/
	void initEvent(int nNum);               //初始化事件
	void resetEvent(int nIndex = -1);       //复位事件 nIndex=-1 复位所有事件 nIndex 复位指定事件
	bool setEvent(int nIndex);                //设置事件
	int waitForObjects(int nTime = 1000000000); //nTime等待时间
protected:
	virtual void _workRun() {};
	bool m_bThreadStart;                    //线程是否正在运行
	bool m_bThreadStop;   //线程是否被停止
private:
	int  m_nNumber;                      //结束线程计数
	QVector<bool>m_vecEvent;             //事件数组
	QMutex *m_pSysMutex;          //现场同步锁
	QWaitCondition *m_pWaitCondition;   //线程同步信号

};

#endif